<template>
  <div>
    <el-row :gutter="30">
      <el-col :span="20" style="margin:20px 0px 0px 100px;">
        <!-- 表格展示数据 -->
        <el-table :data="list" border style="width:1100px;">
          <el-table-column fixed prop="id" label="序号" width="100">
          </el-table-column>
          <el-table-column prop="name" label="员工名称" width="100">
          </el-table-column>
          <el-table-column prop="username" label="用户账号" width="120">
          </el-table-column>
          <el-table-column prop="email" label="用户邮箱" width="160">
          </el-table-column>
          <el-table-column prop="phone" label="手机号" width="120">
          </el-table-column>
          <el-table-column prop="avatar" label="员工头像" width="120">
            <template slot-scope="scope">
              <el-image
                  style="width: 50px; height: 50px"
                  :src="scope.row.avatar"
                  fit="contain">
              </el-image>
            </template>
          </el-table-column>

          <el-table-column fixed="right" label="操作" width="300px">
            <template slot-scope="scope">
              <!-- 这块下面是修改按钮 -->
              <el-button type="primary" @click="initStaff(scope.row)">修改
              </el-button>
              <!-- 这块下面是上架按钮 -->
              <el-button type="info" v-if="scope.row.foodStatus == 0" @click="shangFoodStatus(scope.row.id)">未售
              </el-button>
              <!-- 这块下面是下架按钮 -->
              <el-button type="success" v-if="scope.row.foodStatus == 1" @click="xiaFoodStatus(scope.row.id)">在售
              </el-button>
              <!-- 这块下面是删除按钮 -->
              <el-button type="danger" @click="deleteFoodById(scope.row.id)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog title="员工信息修改" :visible.sync="sttaffVisible" center width="37%">
      <el-form :model="staff">
        <el-form-item label="账号">
          <!--autocomplete="off" 禁止自动补全  -->
          <el-col :span="18">
            <el-input v-model="staff.username" autocomplete="off" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名">
          <!--autocomplete="off" 禁止自动补全  -->
          <el-col :span="18">
            <el-input v-model="staff.name" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="邮箱">
          <!--autocomplete="off" 禁止自动补全  -->
          <el-col :span="18">
            <el-input v-model="staff.email" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="电话">
          <!--autocomplete="off" 禁止自动补全  -->
          <el-col :span="18">
            <el-input v-model="staff.phone" autocomplete="off" ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="用户头像">
          <el-upload
              name="foodFile"
              class="avatar-uploader"
              action="http://localhost:9527/food/upload"
              :show-file-list="false"
              :on-success="fileUploadSuccess"
              :before-upload="beforeAvatarUpload"
          >
            <img v-if="staff.avatar" :src="staff.avatar" class="avatar" style="width: 200px; height: 200px">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sttaffVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveFood">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Staff",
  data(){
    return {
      list: [],
      staff: {},
      sttaffVisible:false
    };
  },
  methods:{
    getAllStaff(){
      //请求方式为get
      this.$axios.get("http://localhost:9527/backstagesupporter/main/hfstaff").then(res => {//获取返回结果
        if (res.data.code == 200) {
          this.list = res.data.data;
        }
        // console.log(this.list)
      }).catch(e => {
        console.log(e)
      });
    },
    initStaff(row){
      this.staff = row
      this.sttaffVisible = true
    }
  },
  created() {
    this.getAllStaff()
  }
}
</script>

<style scoped>

</style>
